package com.dasel.math

import groovyx.gpars.ParallelEnhancer

/**
 * Created by IntelliJ IDEA.
 * User: benoit
 * Date: 28-Feb-2010
 * Time: 18:12:22
 * To change this template use File | Settings | File Templates.
 */

class Grid {
    Integer rows
    Integer cols
    Object[][] matrix

    Grid plus(Grid right) {
        if (rows != right.rows) throw new Exception("Matrix A and Matrix B must be same size");
        def results = new Object[rows][cols];
        for (int i = 0; i < rows; i++) {
            for (int j = 0; j < cols; j++) {
                results[i][j] = this.matrix[i][j] + right.matrix[i][j]
            }
        }
        return new Grid(matrix: results, rows: rows, cols: cols)
    }


    Grid plus(Number right) {
        def results = new Object[rows][cols];
        for (int i = 0; i < rows; i++) {
            for (int j = 0; j < cols; j++) {
                results[i][j] = this.matrix[i][j] + right
            }
        }
        return new Grid(matrix: results, rows: rows, cols: cols)
    }

  Grid multiply(Grid right) {
        if (rows != right.rows) throw new Exception("Matrix A and Matrix B must be same size");
        def results = new Object[rows][cols];
        for (int i = 0; i < rows; i++) {
            for (int j = 0; j < cols; j++) {
                results[i][j] = this.matrix[i][j] * right.matrix[i][j]
            }
        }
        return new Grid(matrix: results, rows: rows, cols: cols)
    }


    Grid multiply(Number right) {
        def results = new Object[rows][cols];
        for (int i = 0; i < rows; i++) {
            for (int j = 0; j < cols; j++) {
                results[i][j] = this.matrix[i][j] * right
            }
        }
        return new Grid(matrix: results, rows: rows, cols: cols)
    }
}